package com.eling.elcms.travel.service.impl;

import com.eling.elcms.basedoc.model.BusinessMessage;
import com.eling.elcms.basedoc.model.Room;
import com.eling.elcms.basedoc.model.Room.Status;
import com.eling.elcms.basedoc.model.TargetType;
import com.eling.elcms.basedoc.model.TaskType;
import com.eling.elcms.basedoc.service.IBusinessMessageManager;
import com.eling.elcms.basedoc.service.IRoomManager;
import com.eling.elcms.core.AppContext;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.system.model.CommonUser;
import com.eling.elcms.travel.dao.ICheckInDao;
import com.eling.elcms.travel.model.*;
import com.eling.elcms.travel.model.CheckIn.CheckOutStatus;
import com.eling.elcms.travel.model.CheckInImplement.DataSource;
import com.eling.elcms.travel.model.CheckInImplement.PaymentMethod;
import com.eling.elcms.travel.model.CheckInImplement.StatementStatus;
import com.eling.elcms.travel.model.GroupReserve.CheckInType;
import com.eling.elcms.travel.model.NonMemberGroup.SignUpType;
import com.eling.elcms.travel.model.PlanItemGroup.CheckInStatus;
import com.eling.elcms.travel.model.view.AdjustGroupView;
import com.eling.elcms.travel.model.view.CheckInView;
import com.eling.elcms.travel.model.view.CheckOutView;
import com.eling.elcms.travel.service.*;
import com.eling.elcms.travel.util.DateHandlerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class CheckInManagerImpl extends GenericManagerImpl<CheckIn, Long> implements ICheckInManager {

	ICheckInDao checkInDao;

	@Autowired
	public void setDao(ICheckInDao dao) {
		this.dao = dao;
		this.checkInDao = dao;
	}

	@Autowired
	private IRoomManager roomManager;
	@Autowired
	private IRoomRegisterManager roomRgisterManager;
	@Autowired
	private ISignUpRegisterManager signUpRegisterManager;
	@Autowired
	private IPlanItemGroupManager planItemGroupManager;
	@Autowired
	private INonMemberGroupManager nonMemberGroupManager;
	@Autowired
	private IGroupReserveManager groupReserveManager;
	@Autowired
	private ICheckOutSettlementManager checkOutSettlementManager;
	@Autowired
	private IRoomPersonalInfoManager roomPersonalInfoManager;
	@Autowired
	private ICheckInImplementManager checkInImplementManager;
	@Autowired
	private ITravelContractManager travelContractManager;
	@Autowired
	private IWelfareConsumptionCouponManager welfareConsumptionCouponManager;
	@Autowired
	private IWelfareConsumptionCouponDetailManager welfareConsumptionCouponDetailManager;
	@Autowired
	private ICheckOutDealManager checkOutDealManager;
	@Autowired
	private ICheckOutSetlDetailManager checkOutSetlDetailManager;
	@Autowired
	private IRoomOccupancyManager roomOccupancyManagerImpl;
	@Autowired
 	private IBusinessMessageManager businessMessageManager;

	@Override
	public List<CheckInView> queryAll(CheckIn car) {
		List<CheckInView> returnlist = checkInDao.queryAll(car);
		return returnlist;
	}

	@Override
	public CheckIn checkOut(CheckOutView checkOutView) {
		if(checkOutView.getMemDataSource()){
			CheckIn checkIn = get(checkOutView.getPkCheckIn());
			Set<RoomPersonalInfo> roomPersonalInfos = checkIn.getCheckInImplement().getRoomPersonalInfos();
			
			// 更新数据库中的每条报名的是否退房
			List<RoomPersonalInfo> roomlist = checkOutView.getList();
			List<SignUpRegister> signUplist = new ArrayList<SignUpRegister>();
			// 每个房间的入住人数map
			Map<Long, Integer> roomCheckInNumber = new HashMap<>();
			
			// 推结算单的房间信息
			List<RoomPersonalInfo> roomPerCheckOutList = new ArrayList<RoomPersonalInfo>();
			// 删除调整未被清楚的退团人员数据
			Set<RoomPersonalInfo> roomPerSet = new HashSet<RoomPersonalInfo>();
			for (RoomPersonalInfo room : roomPersonalInfos) {
				if(room.getSignUpRegister().getExitGroup() == null
						|| !room.getSignUpRegister().getExitGroup()){
					Long pkRoom = room.getRoomRegister().getRoom().getPkRoom();
					if (roomCheckInNumber.containsKey(pkRoom)) {
						roomCheckInNumber.put(pkRoom, roomCheckInNumber.get(pkRoom)+1) ;
					} else {
						roomCheckInNumber.put(pkRoom, 1);
					}
				}else{
					roomPerSet.add(room);
				}
				for (RoomPersonalInfo roomrpi : roomlist) {
					if (roomrpi.getPkRoomPersonalInfo().equals(room.getPkRoomPersonalInfo())
							&& roomrpi.getSignUpRegister().getCheckOut() != null
							&& roomrpi.getSignUpRegister().getCheckOut()) {
						SignUpRegister signup = room.getSignUpRegister();
						signup.setCheckOut(roomrpi.getSignUpRegister().getCheckOut());
						signup.setCheckOutDate(roomrpi.getSignUpRegister().getCheckOutDate());
						signUplist.add(signup);
						if(room.getSignUpRegister().getExitGroup() == null
								|| !room.getSignUpRegister().getExitGroup()){
							roomPerCheckOutList.add(room);
						}
						break;
					}
				}
			}
			signUplist = signUpRegisterManager.save(signUplist);
			// 保存房间 水表 电表
			RoomRegister roomRegister = checkIn.getRoomRegister();
			roomRegister.setCheckOutElectricMeter(checkOutView.getCheckOutElectricMeter());
			// 退住冷水
			roomRegister.setCheckOutWaterMeter(checkOutView.getCheckOutWaterMeter());
			// 退住热水
			roomRegister.setCheckOutHotWaterMeter(checkOutView.getCheckOutHotWaterMeter());
			roomRgisterManager.save(roomRegister);
			
			for (RoomPersonalInfo roomPersonalInfo : roomPerCheckOutList) {
				Date checkOutDate = roomPersonalInfo.getSignUpRegister().getCheckOutDate();
				Boolean checkOut = roomPersonalInfo.getSignUpRegister().getCheckOut();
				roomPersonalInfo = roomPersonalInfoManager.get(roomPersonalInfo.getPkRoomPersonalInfo());
				SignUpRegister surToSave = roomPersonalInfo.getSignUpRegister();
				
				surToSave.setCheckOutDate(checkOutDate);
				surToSave.setCheckOut(checkOut);
				signUpRegisterManager.save(surToSave);
				Double roomPrice = roomRegister.getCheckInPrice() == null ? 0 : roomRegister.getCheckInPrice();
				// 生成收费单
				CheckOutSettlement checkOutSettlement = checkOutSettlementManager.createCheckOutSettlement(roomPersonalInfo,
						roomPrice*DateHandlerUtil.daysOfTwoDate(checkIn.getCheckInDate(), checkIn.getCheckOutDate()),
						// 同房间的入住人数
						roomCheckInNumber.get(roomPersonalInfo.getRoomRegister().getRoom().getPkRoom()),
						checkIn.getCheckInDate(), checkIn.getCheckOutDate());
				
				// 生成交通往返费
				checkOutSettlement = checkOutSettlementManager.creatPickUp(checkOutSettlement,roomPersonalInfo.getCheckInImplement());
				checkOutSettlement.setOther(roomPersonalInfo.getChangeRoomFee());
				roomPersonalInfo.setCheckOutSettlement(checkOutSettlement);
				roomPersonalInfoManager.save(roomPersonalInfo);
			}
			// 删除调整未被清楚的退团人员数据
			if(roomPerSet != null && !roomPerSet.isEmpty()){
				roomPersonalInfoManager.remove(new ArrayList<>(roomPerSet));
			}
			
			// 全部退住
			if (checkOutView.isCheckOut()) {
				checkIn.setCheckOutStatus(CheckOutStatus.CheckOut);
				checkIn = save(checkIn);

				boolean flag = true;
				for (RoomPersonalInfo roomPersonalInfo : roomPerCheckOutList) {
					if (!roomPersonalInfo.getSignUpRegister().getCheckOut()) {
						flag = false;
					}
				}
				if (flag) {
					// 单个房间全部退住，则获取该团所有的房间退住信息
					CheckIn queryCheckin = new CheckIn();
					queryCheckin.setCheckInImplement(checkIn.getCheckInImplement());
					List<CheckIn> queryCheckinList = query(queryCheckin);
					for(CheckIn ci : queryCheckinList){
						// 同一个团的多个入住checkin数据的房间是一个，则都更新为已查房状态
						if(ci.getRoomRegister().getRoom().getPkRoom().equals(checkIn.getRoomRegister().getRoom().getPkRoom())
								&& !ci.getPkCheckIn().equals(checkIn.getPkCheckIn())){
							ci.setCheckOutStatus(CheckOutStatus.CheckOut);
							save(ci);
						}
						if(ci.getCheckOutStatus().equals(CheckOutStatus.NoCheckOut)){
							flag = false;
						}
					}
					if(flag){	// 该团所有房间都已退住（查房），则回写团信息
						PlanItemGroup planItemGroup = checkIn.getCheckInImplement().getGroupReserve().getPlanItemGroup();
						planItemGroup.setCheckInStatus(PlanItemGroup.CheckInStatus.Finish);
						planItemGroupManager.save(planItemGroup);
						businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.MemSettlement,planItemGroup.getPkPlanItemGroup()));
					}
				}

			}
			return checkIn;
		}else{
			return saveNonMemCheckOut(checkOutView);
		}
	}
	
	private CheckIn saveNonMemCheckOut(CheckOutView checkOutView){
		CheckIn checkIn = get(checkOutView.getPkCheckIn());
		Set<RoomPersonalInfo> roomPersonalInfos = checkIn.getCheckInImplement().getRoomPersonalInfos();
		
		// 更新数据库中的每条报名的是否退房
		List<RoomPersonalInfo> roomlist = checkOutView.getList();
		List<SignUpRegister> signUplist = new ArrayList<SignUpRegister>();
		// 每个房间的入住人数map
		Map<Long, Integer> roomCheckInNumber = new HashMap<>();
		
		// 推结算单的房间信息
		List<RoomPersonalInfo> roomPerCheckOutList = new ArrayList<RoomPersonalInfo>();
		// 删除调整未被清楚的退团人员数据
		Set<RoomPersonalInfo> roomPerSet = new HashSet<RoomPersonalInfo>();
		for (RoomPersonalInfo room : roomPersonalInfos) {		// 数据库-数据
			// 不推送退团人员的数据
			if(room.getNonMemberRegister().getSignUpRegister().getExitGroup() == null
					|| !room.getNonMemberRegister().getSignUpRegister().getExitGroup()){
				Long pkRoom = room.getRoomRegister().getRoom().getPkRoom();
				if (roomCheckInNumber.containsKey(pkRoom)) {
					roomCheckInNumber.put(pkRoom, roomCheckInNumber.get(pkRoom)+1) ;
				} else {
					roomCheckInNumber.put(pkRoom, 1);
				}
			}else{
				roomPerSet.add(room);
			}
			
			for (RoomPersonalInfo roomrpi : roomlist) {		// 页面-数据
				if (roomrpi.getPkRoomPersonalInfo().equals(room.getPkRoomPersonalInfo())
						&& roomrpi.getSignUpRegister().getCheckOut() != null
						&& roomrpi.getSignUpRegister().getCheckOut()) {
					SignUpRegister signup = room.getNonMemberRegister().getSignUpRegister();
					signup.setCheckOut(roomrpi.getSignUpRegister().getCheckOut());
					signup.setCheckOutDate(roomrpi.getSignUpRegister().getCheckOutDate());
					signUplist.add(signup);
					roomPerCheckOutList.add(room);
					break;
				}
			}
		}
		signUplist = signUpRegisterManager.save(signUplist);
		// 保存房间 水表 电表
		RoomRegister roomRegister = checkIn.getRoomRegister();
		roomRegister.setCheckOutElectricMeter(checkOutView.getCheckOutElectricMeter());
		// 退住冷水
		roomRegister.setCheckOutWaterMeter(checkOutView.getCheckOutWaterMeter());
		// 退住热水
		roomRegister.setCheckOutHotWaterMeter(checkOutView.getCheckOutHotWaterMeter());
		roomRgisterManager.save(roomRegister);
		
		for(RoomPersonalInfo iRpi: roomPerCheckOutList){
			//获取入住价
			CheckOutSettlement checkOutSettlement = checkOutSettlementManager.createCheckOutSettlement(
					iRpi, iRpi.getRoomRegister().getCheckInPrice(),
					roomCheckInNumber.get(iRpi.getRoomRegister().getRoom().getPkRoom()),checkIn.getCheckInDate(),checkIn.getCheckOutDate());
			// 生成交通往返费
			checkOutSettlement = checkOutSettlementManager.creatPickUp(checkOutSettlement,iRpi.getCheckInImplement());
			checkOutSettlement.setOther(iRpi.getChangeRoomFee());
			iRpi.setCheckOutSettlement(checkOutSettlement);
			roomPersonalInfoManager.save(iRpi);
		}
		// 删除调整未被清楚的退团人员数据
		if(roomPerSet != null && !roomPerSet.isEmpty()){
			roomPersonalInfoManager.remove(new ArrayList<>(roomPerSet));
		}
		
		// 全部退住
		if (checkOutView.isCheckOut()) {
			checkIn.setCheckOutStatus(CheckOutStatus.CheckOut);
			checkIn = save(checkIn);
			boolean flag = true;
			for (RoomPersonalInfo roomPersonalInfo : roomPerCheckOutList) {
				if (!roomPersonalInfo.getNonMemberRegister().getSignUpRegister().getCheckOut()) {
					flag = false;
				}
			}
			if (flag) {
				// 单个房间全部退住，则获取该团所有的房间退住信息
				CheckIn queryCheckin = new CheckIn();
				queryCheckin.setCheckInImplement(checkIn.getCheckInImplement());
				List<CheckIn> queryCheckinList = query(queryCheckin);
				for(CheckIn ci : queryCheckinList){
					// 同一个团的多个入住checkin数据的房间是一个，则都更新为已查房状态
					if(ci.getRoomRegister().getRoom().getPkRoom().equals(checkIn.getRoomRegister().getRoom().getPkRoom())
							&& !ci.getPkCheckIn().equals(checkIn.getPkCheckIn())){
						ci.setCheckOutStatus(CheckOutStatus.CheckOut);
						save(ci);
					}
					if(ci.getCheckOutStatus().equals(CheckOutStatus.NoCheckOut)){
						flag = false;
					}
				}
				if(flag){	// 该团所有房间都已退住（查房），则回写团信息
					NonMemberGroup nonMemberGroup = checkIn.getCheckInImplement().getNonMemGroupReserve().getNonMemberGroup();
					nonMemberGroup.setStatus(com.eling.elcms.travel.model.NonMemberGroup.Status.CheckOut);
					nonMemberGroupManager.save(nonMemberGroup);
					CheckOutDeal checkOutDeal = new CheckOutDeal();
					checkOutDeal.setCheckInImplement(checkIn.getCheckInImplement());
					List<CheckOutDeal> checkOutDealList = checkOutDealManager.query(checkOutDeal);
					if (checkOutDealList.isEmpty()) {
						checkOutDeal.setStatementStatus(StatementStatus.NoStatement);
						checkOutDeal.setVersion(0);
						// 推送结算主表
						checkOutDeal = checkOutDealManager.save(checkOutDeal);
						businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.CheckOutDeal,nonMemberGroup.getPkNonMemberGroup()));
						List<CheckOutSetlDetail> cosdList = new ArrayList<>();
						for (RoomPersonalInfo rpi : checkIn.getCheckInImplement().getRoomPersonalInfos()) {
							// 只推送非退团人员的结算
							if(rpi.getNonMemberRegister().getSignUpRegister().getExitGroup() == null || 
									!rpi.getNonMemberRegister().getSignUpRegister().getExitGroup()){
								CheckOutSetlDetail checkOutSetlDetail = new CheckOutSetlDetail();
								checkOutSetlDetail.setCheckOutDeal(checkOutDeal);
								checkOutSetlDetail.setRoomPersonalInfo(rpi);
								checkOutSetlDetail.setVersion(0);
								cosdList.add(checkOutSetlDetail);
							}
						}

						// 推送结算子表
						checkOutSetlDetailManager.save(cosdList);
					}
				}
			}
		}
		return checkIn;
	}

	@Override
	public List<CheckOutSettlement> checkOutSettlementSave(List<CheckOutSettlement> list, Double balance,
			List<PaymentMethod> paymentMethods, String description,CheckInImplement checkInImp) {
		List<CheckOutSettlement> listReturn = checkOutSettlementManager.save(list);
		// 退房结算时推送福利券明细
		List<RoomPersonalInfo> rooms = new ArrayList<RoomPersonalInfo>();
		List<Long> pkList = new ArrayList<Long>();
		for (CheckOutSettlement checkOut : listReturn) {
			if (checkOut.getCheckOutSettlement()) {
				pkList.add(checkOut.getPkCheckOutSettlement());
			}
		}
		RoomPersonalInfo room = new RoomPersonalInfo();
		PropertyUtils.setProperty(room, "checkOutSettlement.pkCheckOutSettlementIn", pkList);
		rooms = roomPersonalInfoManager.query(room);
		List<Long> tcList = new ArrayList<Long>();
		for (RoomPersonalInfo personalInfo : rooms) {
			if(personalInfo.getSignUpRegister().getTravelContract()!=null){
				tcList.add(personalInfo.getSignUpRegister().getTravelContract().getPkTravelContract());
			}
		}
		// 查询消费券
		WelfareConsumptionCoupon welfarecc = new WelfareConsumptionCoupon();
		PropertyUtils.setProperty(welfarecc, "travelContract.pkTravelContractIn", tcList);
		List<WelfareConsumptionCoupon> welfareccs = welfareConsumptionCouponManager.query(welfarecc);
		if (!welfareccs.isEmpty()) {
			for (int i = 0; i < welfareccs.size(); i++) {
				for (int j = 0; j < rooms.size(); j++) {
					if (welfareccs.get(i).getTravelContract().getPkTravelContract()
							.equals(rooms.get(j).getSignUpRegister().getTravelContract().getPkTravelContract())) {
						Double s = welfareccs.get(i).getBalance() - rooms.get(j).getCheckOutSettlement().getCoupon();
						if (s > 0) {
							welfareccs.get(i).setBalance(s);
							WelfareConsumptionCoupon w = welfareConsumptionCouponManager.save(welfareccs.get(i));
							WelfareConsumptionCouponDetail welfareccd = new WelfareConsumptionCouponDetail();
							welfareccd.setPrice(rooms.get(j).getCheckOutSettlement().getCoupon());
							welfareccd.setWelfareConsumptionCoupon(w);
							welfareccd.setOperateDate(new Date());
							welfareccd.setOperator((CommonUser) AppContext.curUser());
							welfareccd.setServicePoint(((CommonUser) AppContext.curUser()).getServicePoint());
							welfareccd.setOperateStatus(WelfareConsumptionCouponDetail.OperateStatus.Consumption);
							welfareccd = welfareConsumptionCouponDetailManager.save(welfareccd);
						}
					}
				}
			}
		}

		boolean flag = true;
		for (CheckOutSettlement cos : listReturn) {
			if (cos.getCheckOutSettlement() == null || !cos.getCheckOutSettlement()) {
				flag = false;
			}
		}
		if (flag) {
			CheckOutSettlement c = listReturn.get(0);
			RoomPersonalInfo roomPersonalInfo = new RoomPersonalInfo();
			roomPersonalInfo.setCheckOutSettlement(c);
			roomPersonalInfo = roomPersonalInfoManager.query(roomPersonalInfo).get(0);

			CheckInImplement checkInImplement = roomPersonalInfo.getCheckInImplement();
			checkInImplement.setBalance(balance);
			checkInImplement.setPaymentMethods(new HashSet<>(paymentMethods));
			if (description != null) {
				checkInImplement.setDescription(description);
			}
			checkInImplement.setStatementDate(new Date());
			checkInImplement.setStatementStatus(CheckInImplement.StatementStatus.Statement);
			if(checkInImp!=null){
				checkInImplement.setCompany(checkInImp.getCompany());
				checkInImplement.setPerName(checkInImp.getPerName());
				checkInImplement.setPhone(checkInImp.getPhone());
				checkInImplement.setOnCreditMoney(checkInImp.getOnCreditMoney());
				checkInImplement.setIsSales(checkInImp.getIsSales());
			}
			checkInImplement = checkInImplementManager.save(checkInImplement);

			// 扣除余额
			Set<RoomPersonalInfo> infos = checkInImplement.getRoomPersonalInfos();
			for (RoomPersonalInfo roomPer : infos) {
				if(roomPer.getSignUpRegister().getTravelContract() != null){
					TravelContract contract =roomPer.getSignUpRegister().getTravelContract();
					CheckOutSettlement checkOutSettlement = roomPer.getCheckOutSettlement();
					if (checkOutSettlement.getBedSubsidyUnit() != null && checkOutSettlement.getBedSubsidyUnit() != 0D) {
						contract.setBalTime(contract.getBalTime() - checkOutSettlement.getBedSubsidyUnit());
					} else if(checkOutSettlement.getBedSubsidy() != null && checkOutSettlement.getBedSubsidy() != 0D) {
						contract.setBalance(contract.getBalance() - checkOutSettlement.getExpense());
					}
					travelContractManager.save(contract);
				}
			}

			// 退房结算时把房间状态改为脏房,并且删除房间占用数据
			Set<RoomPersonalInfo> rmPerInfoSet = checkInImplement.getRoomPersonalInfos();
			List<Room> rmList = new ArrayList<>();
			for (RoomPersonalInfo rmPerInfo : rmPerInfoSet) {
				Room rm = rmPerInfo.getRoomRegister().getRoom();
				rm.setStatus(Status.Dirty);
				rmList.add(rm);
			}
			if (!rmList.isEmpty()) {
				roomManager.save(rmList);
			}
			roomOccupancyManagerImpl.removeRoomOccup(checkInImplement.getGroupReserve().getPlanItemGroup());
			businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.MemSettlementList,c.getPkCheckOutSettlement()));

		}
		return listReturn;
	}

	/**
	 * 查询组团退房确认列表
	 * 
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@Override
	public List<CheckIn> queryCheckOutConfirm(CheckIn cond) {
		PropertyUtils.setProperty(cond, "checkInImplement.groupReserve.checkInType", "Organization");
		return query(cond);
	}

	@Override
	public List<AdjustGroupView> queryAdjust(CheckInImplement cii, String destnSerPoint) {
		List<AdjustGroupView> returnList = new ArrayList<>();

		String[] longBooleanStr = destnSerPoint.split(",");
		String booleanStr = longBooleanStr[1];
		if (Boolean.parseBoolean(booleanStr)) {
			// 查询散客团
			NonMemberGroup nonMemberGroup = new NonMemberGroup();
			PropertyUtils.setProperty(nonMemberGroup, "servicePoint.pkServicePoint", Long.parseLong(longBooleanStr[0]));
			PropertyUtils.setProperty(nonMemberGroup, "checkInDate", cii.getGroupReserve().getCheckInDate());
			PropertyUtils.setProperty(nonMemberGroup, "checkInDateEnd", cii.getGroupReserve().getCheckOutDate());
			PropertyUtils.setProperty(nonMemberGroup, "statusIn", "Effective,Confirm,Cancel");
			List<NonMemberGroup> nonMemGroupList = nonMemberGroupManager.query(nonMemberGroup);
			for (NonMemberGroup non : nonMemGroupList) {
				if(non.getStatus().equals(com.eling.elcms.travel.model.NonMemberGroup.Status.Confirm) 
						&& non.getSignUpType().equals(SignUpType.NonMember)
						&& non.getChargeDeposit()){
					continue;
				}
				AdjustGroupView view = new AdjustGroupView();
				view.setNonMemberGroup(non);
				view.setGroupStatus(GroupStatus.Reserve);
				view.setDataSource(DataSource.NonMember);
				view.setGroupType(GroupType.TravelGroup); // TODO
				returnList.add(view);
			}
		} else {
			// 查询老人团
			PlanItemGroup planItemGroup = new PlanItemGroup();
			PropertyUtils.setProperty(planItemGroup, "planItem.destination.pkDestination",
					Long.parseLong(longBooleanStr[0]));
			PropertyUtils.setProperty(planItemGroup, "planItem.startDate", cii.getGroupReserve().getCheckInDate());
			PropertyUtils.setProperty(planItemGroup, "planItem.startDateEnd", cii.getGroupReserve().getCheckOutDate());
			PropertyUtils.setProperty(planItemGroup, "checkInStatusIn", "Initial,Reserve");
			PropertyUtils.setProperty(planItemGroup, "signUpStatusIn", "Confirm,Review,AdjustmentReview");
			List<PlanItemGroup> planGroupList = planItemGroupManager.query(planItemGroup);
			List<Long> pkPlanIGList = new ArrayList<>();
			List<GroupReserve> groupResList = new ArrayList<>();
			if (!planGroupList.isEmpty()) {
				pkPlanIGList = planGroupList.stream().map(a -> a.getPkPlanItemGroup()).collect(Collectors.toList());
				GroupReserve groupReserve = new GroupReserve();
				PropertyUtils.setProperty(groupReserve, "planItemGroup.pkPlanItemGroupIn", pkPlanIGList);
				groupResList = groupReserveManager.query(groupReserve);
			}
			for (PlanItemGroup pig : planGroupList) {
				AdjustGroupView view = new AdjustGroupView();
				if (pig.getCheckInStatus() != null && pig.getCheckInStatus().equals(CheckInStatus.Initial)) {
					// 判断组团类型或入住类型
					if (pig.getAlliance()) {
						view.setGroupType(GroupType.Alliance);
					} else {
						view.setGroupType(GroupType.Organization);
					}
					view.setGroupStatus(GroupStatus.SignUp);
				} else {
					// 判断组团类型或入住类型
					for (GroupReserve gr : groupResList) {
						if (gr.getPlanItemGroup().getPkPlanItemGroup().equals(pig.getPkPlanItemGroup())) {
							List<Room> rooms=new ArrayList<Room>();
							for(RoomRegister room:gr.getRoomRegisters()){
								rooms.add(room.getRoom());
							}
							view.setRoomList(rooms);
							view.setGroupReserve(gr);
							pig.getPlanItem().setStartDate(gr.getCheckInDate());
							pig.getPlanItem().setEndDate(gr.getCheckOutDate());
							if (pig.getAlliance()) {
								if (gr.getCheckInType().equals(CheckInType.Alliance)) {
									view.setGroupType(GroupType.AllianceToAlliance);
								} else {
									view.setGroupType(GroupType.AllianceToOrg);
								}
								break;
							} else {
								if (gr.getCheckInType().equals(CheckInType.Organization)) {
									view.setGroupType(GroupType.OrgToOrg);
								} else {
									view.setGroupType(GroupType.OrgToAlliance);
								}
								break;
							}
						}
					}
					view.setGroupStatus(GroupStatus.Reserve);
				}
				view.setPlanItemGroup(pig);
				view.setDataSource(DataSource.GroupReserve);
				returnList.add(view);
			}
		}

		return returnList;
	}
}